package com.example.study.controller;

import com.example.study.common.api.ResultUtil;
import com.example.study.model.ClassPO;
import com.example.study.model.ClassVO;
import com.example.study.service.ClassService;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("/class")
@Api(tags = "班级管理")
public class ClassController {

    @Resource
    private ClassService classService;

    /**
     * 创建班级
     */
    @ApiOperation("创建班级")
    @RequestMapping(value = "/create_class", method = RequestMethod.POST)
    @ResponseBody
    public ResultUtil createClass(@RequestBody @Validated ClassVO clazz) {
        return classService.saveClass(clazz);
    }

    /**
     * 获取全部班级
     */
    @ApiOperation("获取全部班级")
    @RequestMapping(value = "/list_class", method = RequestMethod.GET)
    @ResponseBody
    public ResultUtil getClassList() {
        return classService.getClassList();
    }

    /**
     * 分页获取班级
     */
    @ApiOperation("分页获取班级")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码(默认第一页)", dataType = "string", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量(默认十条数据)", dataType = "string", paramType = "query", example = "10")})
    @RequestMapping(value = "/page_class", method = RequestMethod.GET)
    @ResponseBody
    public ResultUtil getClassPage(@RequestParam(value = "pageNum", defaultValue = "1") int pageIndex,
                                   @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        return classService.getClassPage(pageIndex, pageSize);
    }

    /**
     * 根据ID查询班级信息
     */
    @ApiOperation("根据ID获取班级")
    @RequestMapping(value = "/class/{id}", method = RequestMethod.GET)
    @ResponseBody
    public ResultUtil getClassById(@PathVariable(value = "id") long id) {
        return classService.getClassById(id);
    }

    /**
     * 根据班级ID获取学生与老师信息
     */
    @ApiOperation("根据班级ID获取学生与老师信息")
    @RequestMapping(value = "/stu_teach_by_class_id", method = RequestMethod.GET)
    @ResponseBody
    public ResultUtil getStuTeachByClassId(@RequestParam(value = "classId") long classId) {
        return classService.getStuTeachByClassId(classId);
    }

}
